import { AuditLogService } from './../../service/auditLogService';
import { ServiceManager } from './../../common/serviceFactory/serviceManager';
import { AuditLog } from './../../domain/models/auditLog';
import * as Koa from 'koa';
import { route, RouteOptionsVerify, UsingLock } from "../../common";
import { ServiceException } from '../../common/excpetion';
const auditLogSvr = ServiceManager.Current.GetService<AuditLogService>('AuditLogService');
class AuditLogController {
    @route(new RouteOptionsVerify('GET', '/api/auditLog'))
    async queryAuditLogs(ctx: Koa.Context, next) {
        let params = ctx.query;
        ctx.response.body = await auditLogSvr.QueryAuditLog(params);
        await next();
    }
    @route(new RouteOptionsVerify('POST', '/api/auditLog'))
    async createAuditLog(ctx: Koa.Context, next) {
        let data: AuditLog = ctx.request.body;
        if (!data.id) {
            throw new ServiceException("未传入id！");
        }
        await UsingLock(data.id, async () => {
            data.createTime = Date.now();
            await auditLogSvr.CreateAuditLog(data);
        })
        ctx.response.body = data;
        await next();
    }
    @route(new RouteOptionsVerify('PUT', '/api/auditLog'))
    async updateAuditLog(ctx: Koa.Context, next) {
        ctx.response.body = null;
        await next();
    }
    @route(new RouteOptionsVerify('DELETE', '/api/auditLog'))
    async deleteAuditLog(ctx: Koa.Context, next) {
        ctx.response.body = null;
        await next();
    }
}